package com.study.rabbitmq.dead;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.study.rabbitmq.utils.RabbitMqUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @author ：黄淼淳
 * @description：生产者
 * @date ：2021/12/8 19:14
 */
public class Product {
    public static final String NORMAL_EXCHANGE = "normal_exchange";

    public static void main(String[] args) throws IOException, InterruptedException {
        Channel channel = RabbitMqUtil.getChannel();
        //死信消息时间 设置时间是TTl
        /*AMQP.BasicProperties properties = new AMQP.BasicProperties()
                .builder().expiration("10000").build();*/
        for (int i = 0; i < 11; i++) {
            String message = "info"+i;
            Thread.sleep(1000);
            //设置过期时间的发送消息代码
            //channel.basicPublish(NORMAL_EXCHANGE,"zhangsan",properties,message.getBytes(StandardCharsets.UTF_8));
            //普通发送消息代码
            channel.basicPublish(NORMAL_EXCHANGE,"zhangsan",null,message.getBytes(StandardCharsets.UTF_8));
            System.out.println(message);
        }
    }
}
